package com.example.demo.modules.test.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.util.ResultUtil;
import com.example.demo.common.util.entity.ListSub;
import com.example.demo.common.util.entity.PageFactory;
import com.example.demo.common.util.entity.Result;
import com.example.demo.common.util.entity.ResultEnum;
import com.example.demo.modules.test.dto.student.StudentDTO;
import com.example.demo.modules.test.dto.student.StudentQueryDTO;
import com.example.demo.modules.test.entity.Student;
import com.example.demo.modules.test.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lmy
 * @since 2022-12-28
 */
@RestController
@RequestMapping("/test/student")
@Api(tags = "测试模块")
public class StudentController {

    @Resource
    private IStudentService iStudentService;

    @ApiOperation(value = "学生分页列表", notes = "学生列表")
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public Result<ListSub<StudentDTO>> page(PageFactory pageFactory, StudentQueryDTO queryDTO){
        Page<StudentDTO> page = new Page<>(pageFactory.getStart(), pageFactory.getLength());
        IPage<StudentDTO> iPage = iStudentService.listStudent(page, queryDTO);
        return ResultUtil.success(iPage);
    }

    @ApiOperation(value = "导入学生信息", notes = "导入学生信息")
    @RequestMapping(value = "importStudent", method = RequestMethod.POST)
    public Result importStudent(String filePath){
        ResultEnum result = iStudentService.importStudent(filePath);
        return ResultUtil.info(result);
    }

    @ApiOperation(value = "导出学生信息", notes = "导出学生信息")
    @RequestMapping(value = "exportStudent", method = RequestMethod.GET)
    public Result exportStudent(StudentQueryDTO queryDTO){
        return iStudentService.exportStudent(queryDTO);
    }
}

